package com.sitecsys.utils;

import org.springframework.core.io.ClassPathResource;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;

public class DefaultAvatarUtil {

    private static final byte[] DEFAULT_AVATAR_BYTES;

    static {
        try (InputStream is = new ClassPathResource("/static/img.png").getInputStream();
             ReadableByteChannel rbc = Channels.newChannel(is)) {
            ByteBuffer bb = ByteBuffer.allocate((int) new ClassPathResource("/static/img.png").contentLength());
            rbc.read(bb);
            DEFAULT_AVATAR_BYTES = bb.array();
        } catch (IOException e) {
            throw new RuntimeException("Failed to load default avatar", e);
        }
    }

    public static byte[] getDefaultAvatarBytes() {
        return DEFAULT_AVATAR_BYTES;
    }
}
